package com.kira.scaffoldmvc.Test;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) {
        try {
            // 创建HttpClient实例
            HttpClient client = HttpClient.newHttpClient();

            // 构建请求体
            String jsonBody = "{\"email\":\"1657294032@qq.com\",\"type\":\"register\"}";

            // 创建HttpRequest实例，设置请求URL、请求方式和请求体
            HttpRequest request = HttpRequest.newBuilder()
                   .uri(URI.create("http://47.119.148.251:7000/user/getLogiOtp"))
                   .header("Content-Type", "application/json")
                   .POST(HttpRequest.BodyPublishers.ofString(jsonBody))
                   .build();

            // 发送请求并获取响应
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

            // 处理响应
            System.out.println("响应状态码: " + response.statusCode());
            System.out.println("响应体内容: " + response.body());
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}